//
//  ViewUtils.h
//  FBSocialProject
//
//  Created by ZhangXiaofei on 2017/8/2.
//  Copyright © 2017年 YunJing. All rights reserved.
//


#import <UIKit/UIKit.h>

/**
 camera 工具分类
 */
@interface UIView (FBCameraViewUtils)

/**
 通过 nib 初始化视图

 @param nibNameOrNil nib 文件名
 @param bundleOrNil nib 所属 bundle 的名称
 @param owner owner
 @return camera 分类视图对象
 */
+ (id)instanceWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)bundleOrNil owner:(id)owner;

/**
 通过 nib 初始化视图
 
 @param nibNameOrNil nib 文件名
 @param bundleOrNil nib 所属 bundle 的名称
 */
- (void)loadContentsWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)bundleOrNil;

//hierarchy

/**
 使用谓词判断当前视图是否满足条件

 @param predicate 谓词对象
 @return 若符合条件返回当前 view，否则返回 nil
 */
- (UIView *)viewMatchingPredicate:(NSPredicate *)predicate;

/**
 查找特定 Class 特定 tag 值的视图对象

 @param tag tag 值
 @param viewClass 视图类名
 @return 若找到返回视图对象，否则返回 nil
 */
- (UIView *)viewWithTag:(NSInteger)tag ofClass:(Class)viewClass;

/**
 判断当前视图是否为某个类型

 @param viewClass 视图类名
 @return 是，返回视图本身，否，返回 nil
 */
- (UIView *)viewOfClass:(Class)viewClass;

/**
 <#Description#>

 @param predicate <#predicate description#>
 @return <#return value description#>
 */
- (NSArray *)viewsMatchingPredicate:(NSPredicate *)predicate;
- (NSArray *)viewsWithTag:(NSInteger)tag;
- (NSArray *)viewsWithTag:(NSInteger)tag ofClass:(Class)viewClass;
- (NSArray *)viewsOfClass:(Class)viewClass;

- (UIView *)firstSuperviewMatchingPredicate:(NSPredicate *)predicate;
- (UIView *)firstSuperviewOfClass:(Class)viewClass;
- (UIView *)firstSuperviewWithTag:(NSInteger)tag;
- (UIView *)firstSuperviewWithTag:(NSInteger)tag ofClass:(Class)viewClass;

- (BOOL)viewOrAnySuperviewMatchesPredicate:(NSPredicate *)predicate;
- (BOOL)viewOrAnySuperviewIsKindOfClass:(Class)viewClass;
- (BOOL)isSuperviewOfView:(UIView *)view;
- (BOOL)isSubviewOfView:(UIView *)view;

- (UIViewController *)firstViewController;
- (UIView *)firstResponder;

//frame accessors

@property (nonatomic, assign) CGPoint origin;
@property (nonatomic, assign) CGSize size;
@property (nonatomic, assign) CGFloat top;
@property (nonatomic, assign) CGFloat left;
@property (nonatomic, assign) CGFloat bottom;
@property (nonatomic, assign) CGFloat right;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;

//bounds accessors

@property (nonatomic, assign) CGSize boundsSize;
@property (nonatomic, assign) CGFloat boundsWidth;
@property (nonatomic, assign) CGFloat boundsHeight;

//content getters

@property (nonatomic, readonly) CGRect contentBounds;
@property (nonatomic, readonly) CGPoint contentCenter;

//additional frame setters

- (void)setLeft:(CGFloat)left right:(CGFloat)right;
- (void)setWidth:(CGFloat)width right:(CGFloat)right;
- (void)setTop:(CGFloat)top bottom:(CGFloat)bottom;
- (void)setHeight:(CGFloat)height bottom:(CGFloat)bottom;

//animation

- (void)crossfadeWithDuration:(NSTimeInterval)duration;
- (void)crossfadeWithDuration:(NSTimeInterval)duration completion:(void (^)(void))completion;

@end

